/**
 * 
 */
package graphs;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.geom.Point2D;
import java.util.Collection;
import javax.swing.JPanel;
import lists.MyArrayList;
//import desl.graphic.geom.*;


/**
 * <h1> Title : GraphPannel </h1>
 * <p> Description : Yeah... </p> 
 * TODO Finish 
 * 
 * @author Adam Blackwell & Ryan Cassidy
 * @since March 2nd 2009
 * @version 1.1
 */
public class GraphPanel extends JPanel {
  private AdjacencyListGraph a;
  private int SIZE = 20;
  
  /**
   * Constructor.
   * 
   * @param a
   */
  public GraphPanel(AdjacencyListGraph a) {
    this.a = a;
  }
  /**
   * Stupid, useless, silly. (Not really, but I don't need it.)
   */
  private static final long serialVersionUID = 1L;
  
  /*
   * (non-Javadoc)
   * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
   */
  public void paintComponent(Graphics g, IGraph graph) {
    super.paintComponent(g);
    // Takes the Vertices out of the graphs hashMap.
    Collection<Vertex> values = graph.getVerticesMap().values();
    // Goes about drawing each vertex and its links for the iterator from the collection.
    for (Vertex v : values) {
      // How big the dots are.
      int vertexSize = this.SIZE;
      // What Color they are, could be abstracted to change with traversing.
      g.setColor(Color.BLACK);
      // Draw the dot.
      g.drawOval(v.getLoc().x - (vertexSize / 2), v.getLoc().y - (vertexSize / 2),
                 vertexSize, vertexSize);
      // Label it.
      g.drawString(v.getInfo(), v.getLoc().x + vertexSize * 2, v.getLoc().y);
      // Create an iterator for its links.
      MyArrayList<Link> links = v.neighbors;
      // Goes about drawing each link in the iterator.
      for (Link l : links) {
        // What color they are, should be abstracted
        g.setColor(Color.BLACK);
        // If the graph is directed use an arrow, which doesn't work right now...
        if (graph.getDirected()) {
//          // This isn't working... I might build my own arrow
//          g.Arrow2D(new Point(v.getLoc().x, v.getLoc().y), 
//                  new Point(l.getDestinationVertex().getLoc().x,
//                     l.getDestinationVertex().getLoc().y));
        // Otherwise draw a line.
        } else {
          g.drawLine(v.getLoc().x, v.getLoc().y, 
                     l.getDestinationVertex().getLoc().x,
                     l.getDestinationVertex().getLoc().y);
        }
      }
    }
  }
}

